package com.ziyun.pop.rest.module.mall.goods;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.service.common.constant.AppType;
import com.service.goods.api.GoodsService;
import com.service.goods.constant.GoodsResult;
import com.service.goods.model.goods.BaseGoodsInfoVO;
import com.service.goods.model.goods.GoodsParamsVO;

import io.renren.common.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

@Api(value = "MallGoodsRestApi", tags = "商城商品服务")
@RestController
@RequestMapping("popApi/mall/goods/")
public class MallGoodsRestApi {
	private static AppType appType = AppType.tuwen_bao;

	@Autowired
	private GoodsService goodsService;

	@ApiOperation(value = "获取商品单品页详情", notes = "")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "goodsId", value = "商品Id", required = true, paramType = "query", dataType = "String") })
	@ApiResponses(value = @ApiResponse(code = 200, message = "获取商品单品页详情", response = BaseGoodsInfoVO.class))
	@GetMapping("/getGoodsInfo")
	public R getGoodsInfo(@RequestParam(value = "goodsId") Long goodsId,
			@RequestParam(required = false, value = "productId") Long productId,
			@RequestParam(required = false, value = "recommendUser") Long recommendUser,
			@RequestParam(required = false, value = "areaId") Integer areaId) {
		GoodsResult<BaseGoodsInfoVO> goodsResult = goodsService.getGoodsInfo(appType, goodsId, productId, recommendUser,
				areaId);
		if (R.isError(goodsResult.getCode())) {
			return R.error(goodsResult.getCode(), goodsResult.getMessage());
		}
		return R.apiOk(goodsResult.getData());
	}

	@ApiOperation(value = "根据选项参数，获取价格详情", notes = "")
	@ApiResponses(value = @ApiResponse(code = 200, message = "获取价格详情"))
	@PostMapping(value = "getPriceInfo")
	public R getPriceInfo(@RequestBody GoodsParamsVO goodsParamsVO) {
		GoodsResult<?> goodsResult = goodsService.getSellPrice(appType, goodsParamsVO);
		if (R.isError(goodsResult.getCode())) {
			return R.error(goodsResult.getCode(), goodsResult.getMessage());
		}
		return R.apiOk(goodsResult.getData());
	}

}
